<template>
  <section>
    <div class="header">
      <h4 class="title">
        <a href="javascript:;" @click="toArticleDetail">{{ articleInfo.title }}</a>
      </h4>
      <div class="post-meta">
        <span class="item"> <CalendarOutlined/> {{ articleInfo.created_time }} </span>
        <!-- <a-divider type="vertical" />
        <span class="item">
          <CalendarOutlined /> {{timeFormat(articleInfo.update_time)}}
        </span> -->
        <a-divider type="vertical"/>
        <span class="item"> <FireOutlined/> {{ articleInfo.views }} 浏览</span>
      </div>
    </div>
    <div class="content">{{ articleInfo.summary }}</div>
    <div class="footer">
      <div class="category-wrap">
        <a class="category-item">
          <BlockOutlined/>
          <span style="margin-left:8px">{{ articleInfo.category_name }}</span>
        </a>
      </div>
      <div class="tag-wrap">
        <a
            class="tag-item"
            v-for="(item, idx) in articleInfo.tags"
            :key="idx"
            :style="{ color: item.color }"
        >
          <TagOutlined/>
          <span style="margin-left:8px">{{ item.name }}</span>
        </a>
      </div>
    </div>
  </section>
</template>
<script>
import {reactive} from "vue"
import {useRouter} from "vue-router"
import {timeFormat} from "@/utils/index"
import dayjs from "dayjs";

export default {
  name: "ArticleCard",
  props: ["info"],
  setup(props) {
    const router = useRouter()
    const articleInfo = reactive(props.info || {})


    articleInfo.created_time = dayjs(articleInfo.created_time).format("YYYY-MM-DD HH:mm")

    const toArticleDetail = () => {
      router.push({path: `/article`, query: {id: articleInfo.id}})
    }

    return {
      articleInfo,
      timeFormat,
      toArticleDetail,
    }
  },
}
</script>
<style scoped lang="less">
section {
  margin-bottom: 2rem;
  padding: 1rem;
  transition: all 0.3s;
  border-radius: 0.5rem;
  background-color: #fff;
  box-shadow: 0 4px 8px 6px rgba(7, 17, 27, 0.08);

  &:hover {
    box-shadow: 0 4px 8px 6px rgba(7, 17, 27, 0.22);
  }

  .header {
    .title {
      text-align: center;
      font-size: 1.8rem;
      color: #666;
      margin: 0;

      a {
        position: relative;
        display: inline-block;
        padding: 0.6rem 3rem;

        &::before {
          visibility: hidden;
          content: "";
          position: absolute;
          width: 10px;
          height: 10px;
          top: 0;
          left: 0;
          transform: translate3d(10px, 10px, 0);
          border: 2px solid;
          border-width: 2px 0 0 2px;
          transition: 0.3s;
          transition-timing-function: cubic-bezier(0.17, 0.67, 0.05, 1.29);
        }

        &::after {
          visibility: hidden;
          content: "";
          position: absolute;
          width: 10px;
          height: 10px;
          right: 0;
          bottom: 0;
          transform: translate3d(-10px, -10px, 0);
          border: 2px solid;
          border-width: 0 2px 2px 0;
          transition: 0.3s;
          transition-timing-function: cubic-bezier(0.17, 0.67, 0.05, 1.29);
        }

        &:hover {
          color: #4dd2ff;

          &::before {
            visibility: visible;
            top: -5px;
            left: -10px;
          }

          &::after {
            visibility: visible;
            bottom: -5px;
            right: -10px;
          }
        }
      }
    }

    .post-meta {
      display: flex;
      flex-direction: row;
      justify-content: center;
      align-items: center;
      font-size: 1.5rem;
      color: #999;

      .item {
        margin: 0 8px;
      }

      :deep(.ant-divider) {
        border-left: 2px solid #666;
      }
    }
  }

  .content {
    padding: 0.8rem 1.4rem;
    font-size: 1.4rem;
    line-height: 2.8rem;
  }

  .footer {
    display: flex;
    align-items: center;
    min-height: 3rem;
    padding-top: 1rem;
    padding-left: 1rem;
    padding-right: 1rem;
    justify-content: space-between;
    border-top: 1px solid rgba(0, 120, 231, 0.05);

    .category-item, .tag-item {
      padding: 4px 8px;
      border-radius: 4px;
      transition: all 0.3s;

      &:hover {
        background: #efefef;
      }
    }
  }
}
</style>
